program MaxStat;

const
   N = 3;

var
   p : array[1..N] of integer; (* ciag liczb *)

function Max() : integer; (* znajdowanie maksimum *)
var
   j, k, m, cnt : integer;
begin	    
   j := N;
   k := N - 1;
   m := p[j];
   cnt := 0;
   while k > 0 do
   begin
      if m < P[k] then
      begin
	 j := k;
	 m := P[k];
	 cnt := cnt + 1;
      end;
      k := k - 1;
   end;
   write(cnt,' ');
   max := m;
end; { max }

procedure Exch(i, j : integer );
var
   t :  integer;
begin
   t := p[i];
   p[i] := p[j];
   p[j] := t;
end; { exch }

procedure Generate(eN : integer );
var
   i : integer;
begin
   if eN = 1 then max();
   for i := 1 to eN do
   begin
      Exch(i, eN);
      Generate(eN-1);
      Exch(i, eN);
   end;
end; { Generate }

var
   i : integer;
begin 
   for i := 1 to N do
      p[i] := i;
   Generate(N);
end.
